import TreeCesiumData from "./layer_tree_data";
import Environment from "@/plugins/utils/environment";
import LayerManager from "@/plugins/mev/layer/LayerManager";

class TilesData extends TreeCesiumData {
    constructor(data, viewer) {
        super(data, viewer);

        this._data = data || { visible: false };
        this._viewer = viewer;
        this._tiles = null;
        this._DataObject = null;
    }

    show() {
        let that = this;
        if (!that.properties) {
            that.properties = {};

            that.properties.lon = parseFloat(that._data.properties.lon);

            that.properties.lat = parseFloat(this._data.properties.lat);

            that.properties.height = parseFloat(this._data.properties.height);
        }
        this._DataObject = new Cesium.Cesium3DTileset({
            /*  url: Environment.getDataBasePath() + "/" + this._data.path*/
            url: this._data.path
        });
        this._viewer.scene.primitives.add(this._DataObject);
        /* let longitude = parseFloat(this._data.properties.lon);
        let latitude = parseFloat(this._data.properties.lat);
        let height = parseFloat(this._data.properties.height);*/
        /*let heading = parseFloat(this._data.properties.heading);*/

        // eslint-disable-next-line no-unused-vars
        this._DataObject.readyPromise.then(function(argument) {
            //经纬度、高转笛卡尔坐标
            var position = Cesium.Cartesian3.fromDegrees(that.properties.lon, that.properties.lat, that.properties.height);
            var mat = Cesium.Transforms.eastNorthUpToFixedFrame(position);
            var rotationX = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(0)));
            Cesium.Matrix4.multiply(mat, rotationX, mat);
            that._DataObject._root.transform = mat;
        });
        /*        that.flyTo(that._DataObject);*/
    }

    close() {
        if (this._DataObject) {
            if (this._viewer.scene.primitives.contains(this._DataObject)) {
                this._viewer.scene.primitives.remove(this._DataObject);
            }

            this._DataObject = null;
        }
    }

    setProperties(props) {
        let that = this;
        that.properties.lon = parseFloat(props.lon);
        that.properties.lat = parseFloat(props.lat);
        that.properties.height = parseFloat(props.height);
        this._DataObject.readyPromise.then(function(argument) {
            //经纬度、高转笛卡尔坐标
            let position = Cesium.Cartesian3.fromDegrees(that.properties.lon, that.properties.lat, that.properties.height);
            let mat = Cesium.Transforms.eastNorthUpToFixedFrame(position);
            let rotationX = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(0)));
            Cesium.Matrix4.multiply(mat, rotationX, mat);
            that._DataObject._root.transform = mat;
        });
        /*that.flyTo();*/
    }
}

export default TilesData;
